﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace DataExportImporter
{
    class Program
    {
        static void Main(string[] args)
        {

            Console.WriteLine("Exporter/Importer V0.1");
            Console.WriteLine("Written By TheSharingCoder");
            Console.WriteLine("");

            if (args.Length < 2)
            {
                Console.WriteLine(@"DataExportImporter.exe export c:\ExportQuerySample.xml c:\outputdata.xml");
                Console.WriteLine(@"DataExportImporter.exe import c:\ExportQuerySample.xml c:\importData.xml");
            }

           

            string Mode = args[0].ToLower();
            string QueryXmlFilename = args[1];
            string InputOutputFilename = args[2];


            switch (Mode)
            {
                case "import": Import(QueryXmlFilename, InputOutputFilename); break;
                case "export": Export(QueryXmlFilename, InputOutputFilename); break;
                default: 
                    Console.WriteLine("Invalid mode: specify either import or export");
                    return;
                    

            }

          
        }

       

        public static void Export(string QueryXmlFilename, string InputOutputFilename)
        {
            Console.WriteLine("Starting Export");

            string OutputPath = InputOutputFilename;
            Export exporter = new Export();

            string ExportQueryXml = System.IO.File.ReadAllText(QueryXmlFilename);

            System.Xml.XmlNode root = exporter.GetListData(ExportQueryXml);
            string xmlContents = root.InnerXml;

            System.IO.File.WriteAllText(OutputPath, xmlContents);
        }


        public static void Import(string QueryXmlFilename, string InputOutputFilename)
        {
            Console.WriteLine("Importing");
            string InputPath = InputOutputFilename;
            Export exporter = new Export();

            string xmlContents =  System.IO.File.ReadAllText(InputPath);
            string importQueryXml = System.IO.File.ReadAllText(QueryXmlFilename);

            Import importer = new Import();
            importer.AddListItem(xmlContents, importQueryXml);


        }


    }
}
